package com.nfc2me;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.widget.Toast;

public class SimpleView extends View {
	/**
	 * 
	 */
	private final N2M_FindCar n2m_FindCar;
	private Bitmap placeImg;
	//private DrawPlaceThread mThread;
	private int _x;
	private int _y;
	public SimpleView(N2M_FindCar n2m_FindCar) {
		super(n2m_FindCar);
		this.n2m_FindCar = n2m_FindCar;
		// TODO Auto-generated constructor stub
		placeImg=BitmapFactory.decodeResource(getResources(), R.drawable.place_icon);
		_x=0;
		_y=0;
		//getHolder().addCallback(this);
		//mThread=new DrawPlaceThread(this);

	}
	public int setX(int x)
	{
		return _x=x;
	}
	public int setY(int y)
	{
		return _y=y;
	}

	protected void onDraw(android.graphics.Canvas canvas) {
		super.onDraw(canvas);
		doDraw(canvas);
	};
	public void doDraw(Canvas canvas)
	{
		canvas.drawBitmap(placeImg,_x,_y,null);
	}
	
	
	@Override
	public boolean onTouchEvent(MotionEvent event) {
		// TODO Auto-generated method stub
		String str="this is the tag";
		Log.d("N2M:","on touch");
		Toast.makeText(this.n2m_FindCar, str.subSequence(0, str.length()-1) ,5);
		return super.onTouchEvent(event);
	}
	/*@Override
	public void surfaceChanged(SurfaceHolder holder, int format, int width,
			int height) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void surfaceCreated(SurfaceHolder holder) {
		// TODO Auto-generated method stub
		  if (!mThread.isAlive()) {
		        mThread = new DrawPlaceThread(this);
		        mThread.setRunning(true);
		        mThread.start();
		    }
		
	}

	@Override
	public void surfaceDestroyed(SurfaceHolder holder) {
		// TODO Auto-generated method stub
	    if (mThread.isAlive()) {
	        mThread.setRunning(false);
	    }
	}*/

}
/*public class DrawPlaceThread extends Thread
{
	private SimpleView mView;
	//private SurfaceHolder mHolder;
	private boolean running=false;
	public DrawPlaceThread(SimpleView sv)
	{
		mView=sv;
		//mHolder=sv.getHolder();
	}
	public void setRunning(boolean run)
	{
		running=run;
	}
	@Override
	public void run()
	{
		Canvas c=null;
		while (running)
		{
			synchronized (mHolder) {
				c=mHolder.lockCanvas();
				if(c!=null)
				{
					mView.doDraw(c);
					mHolder.unlockCanvasAndPost(c);
				}
				
			}
			
		}
	}
}*/